﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Query.Role
{
    /// <summary>
    /// 查询
    /// </summary>
    public class RoleDetailQuery
    {
        public long? RoleId { get; set; } = null;
        public long? RoleIdNE { get; set; } = null;
        public string RoleName { get; set; } = string.Empty;
        public string RoleKey { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public string IsDelete { get; set; } = string.Empty;

        /// <summary>
        /// 模糊查询
        /// </summary>
        public bool FuzzyQuery { get; set; } = false;

        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <returns></returns>
        public Expression<Func<furion.blog.Domain.MySQL.Role, bool>> Exp()
        {
            var exp = Expressionable.Create<furion.blog.Domain.MySQL.Role>();
            exp.AndIF(RoleId!=null,t=>t.RoleId == RoleId);
            exp.AndIF(RoleIdNE!=null,t=>t.RoleId!=RoleIdNE);
            exp.AndIF(!string.IsNullOrWhiteSpace(Status), t => t.Status == Status);
            exp.AndIF(!string.IsNullOrWhiteSpace(IsDelete), t => t.IsDelete == IsDelete);
            if (!FuzzyQuery)
            {
                exp.AndIF(!string.IsNullOrWhiteSpace(RoleName), t => t.RoleName == RoleName);
                exp.AndIF(!string.IsNullOrWhiteSpace(RoleKey), t => t.RoleKey == RoleKey);
            }
            else {
                exp.AndIF(!string.IsNullOrWhiteSpace(RoleName), t => t.RoleName.Contains(RoleName));
                exp.AndIF(!string.IsNullOrWhiteSpace(RoleKey), t => t.RoleKey.Contains(RoleKey));
            }
            return exp.ToExpression();
        }

    }
}
